package com.shangqing.web.controller.system.hail;

import com.shangqing.common.annotation.Log;
import com.shangqing.common.core.controller.BaseController;
import com.shangqing.common.core.domain.AjaxResult;
import com.shangqing.system.service.hail.HailDisasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/hail")
public class HailController extends BaseController {
    @Autowired
    HailDisasterService hailDisasterService;
    @Autowired
    RestTemplate restTemplate;
    @Log(title = "冰雹灾情信息")
    @PreAuthorize("@ss.hasPermi('hail:list')")
    @PostMapping("/list/{Num}")
    public AjaxResult list(@PathVariable("Num") String Num){
        return AjaxResult.success("成功",hailDisasterService.findAllHailList(Num));
    }
    @Log(title = "冰雹全区灾情统计")
    @PostMapping("/hailList/{year}/{quarter}")
    public AjaxResult findHailQuarterList(@PathVariable(value = "year",required = false)String year,
                                          @PathVariable(value = "quarter",required = false)String quarter) {
        Map map=new HashMap();
        Integer Num= hailDisasterService.findHailQuarterList(year, quarter);
        map.put("hailNum",Num);
        map.put("hailYear",year);
        map.put("hailQuarter",quarter);
        return AjaxResult.success("成功",map);
    }
    @Log(title = "各区冰雹灾害发生占比")
    @PostMapping("/hailCount/{year}/{quarter}")
    public AjaxResult findCountHailByCity(@PathVariable(value = "year",required = false)String year,
                                          @PathVariable(value = "quarter",required = false)String quarter){
        logger.info("=========参数========"+year+"===="+quarter);
       return AjaxResult.success("成功",hailDisasterService.findCountHailByCity(year, quarter));
    }
    @Log(title = "本地实时天气")
    @GetMapping("/hail/Weather")
    public AjaxResult showWeather(){
        /*高德API接口*/
        String weatherUrl = "https://restapi.amap.com/v3/weather/weatherInfo?city=640106&key=ed8913582dbbc7b27152c793cfac49b7";
        ResponseEntity<String> weatherEntity = restTemplate.getForEntity(weatherUrl, String.class);
        String weatherBody = weatherEntity.getBody();
        return AjaxResult.success("成功",weatherBody);
    }
    @Log(title = "各区大雾灾情统计")
    @PostMapping("/hail/RegionalStatistics")
    public AjaxResult regionalStatistics(){
        return AjaxResult.success("成功",hailDisasterService.findRegionalDisasterStatistics());
    }

}
